<template>
  <div class="application-management">
    <el-card>
      <div slot="header">
        <span>应聘信息管理</span>
      </div>
      
      <el-table :data="applicationList">
        <el-table-column prop="jobTitle" label="职位名称"></el-table-column>
        <el-table-column prop="applicantName" label="申请人"></el-table-column>
        <el-table-column prop="applyTime" label="申请时间"></el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag :type="getStatusType(scope.row.status)">
              {{ getStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="text" @click="viewDetail(scope.row)">查看详情</el-button>
            <el-button 
              type="text" 
              @click="updateStatus(scope.row, 'accepted')"
              v-if="scope.row.status === 'pending'">
              通过
            </el-button>
            <el-button 
              type="text" 
              @click="updateStatus(scope.row, 'rejected')"
              v-if="scope.row.status === 'pending'">
              拒绝
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 申请详情对话框 -->
    <el-dialog title="申请详情" :visible.sync="detailDialogVisible">
      <div v-if="currentApplication">
        <p><strong>申请人：</strong>{{ currentApplication.applicantName }}</p>
        <p><strong>应聘职位：</strong>{{ currentApplication.jobTitle }}</p>
        <p><strong>申请时间：</strong>{{ currentApplication.applyTime }}</p>
        <p><strong>个人简介：</strong>{{ currentApplication.introduction }}</p>
        <p><strong>工作经验：</strong>{{ currentApplication.experience }}</p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'ApplicationManagement',
  data() {
    return {
      applicationList: [],
      detailDialogVisible: false,
      currentApplication: null
    }
  },
  methods: {
    async fetchApplications() {
      try {
        const response = await this.$axios.get('/api/enterprise/applications')
        this.applicationList = response.data.data
      } catch (error) {
        this.$message.error('获取应聘信息失败')
      }
    },
    getStatusType(status) {
      const statusMap = {
        pending: 'warning',
        accepted: 'success',
        rejected: 'danger'
      }
      return statusMap[status]
    },
    getStatusText(status) {
      const statusMap = {
        pending: '待处理',
        accepted: '已通过',
        rejected: '已拒绝'
      }
      return statusMap[status]
    },
    viewDetail(application) {
      this.currentApplication = application
      this.detailDialogVisible = true
    },
    async updateStatus(application, status) {
      try {
        await this.$axios.put(`/api/enterprise/applications/${application.id}/status`, {
          status: status
        })
        this.$message.success('状态更新成功')
        this.fetchApplications()
      } catch (error) {
        this.$message.error('状态更新失败')
      }
    }
  },
  created() {
    this.fetchApplications()
  }
}
</script>

<style scoped>
.application-management {
  padding: 20px;
}
</style> 